package com.self.baseutile.Utile;

import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import android.preference.PreferenceManager;

import androidx.annotation.Nullable;

import com.alibaba.fastjson.JSON;
import com.self.baseutile.Constants;
import com.self.baseutile.MRWApplication;

import java.util.Set;

/**
 * Craeted by: huangdx
 * Date : 2021/2/24
 * Describe :
 */
public class SharedPreferencesUtil {

    private static SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MRWApplication.mContext);
//    @Nullable
//    public static StoreInfoBean getLoginStore() {
//        String memberJson = sharedPreferences.getString(Constants.LOGIN_STORE_FLAG, "");
//        if(memberJson.isEmpty()){
//            return null;
//        }
//        return JSON.parseObject(memberJson, StoreInfoBean.class);
//    }
    public static void logout() {
        sharedPreferences.edit().clear().commit();
      ///  MRWApplication.storeInfoBean = null;
    }
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public static boolean store(String key, Object value) {
        if (value instanceof Boolean) {
            return sharedPreferences.edit().putBoolean(key, (Boolean) value).commit();
        } else if (value instanceof Integer) {
            return sharedPreferences.edit().putInt(key, (Integer) value).commit();
        } else if (value instanceof Float) {
            return sharedPreferences.edit().putFloat(key, (Float) value).commit();
        } else if (value instanceof String) {
            return sharedPreferences.edit().putString(key, (String) value).commit();
        } else if (value instanceof Long) {
            return sharedPreferences.edit().putLong(key, (Long) value).commit();
        } else if (value instanceof Set) {
            return sharedPreferences.edit().putStringSet(key, (Set<String>) value).commit();
        }
        return false;
    }
}
